package com.csu.mining.adapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.csu.mining.R;
import com.csu.mining.activity.VideoAndDocumentActivity;
import com.csu.mining.views.WEqualsHImageView;

import java.util.ArrayList;
import java.util.List;

public class MiningMenuAdapter extends RecyclerView.Adapter<MiningMenuAdapter.ViewHolder> {

    private Context mContext;

    private int[] icons = {
            R.mipmap.mi1, R.mipmap.mi2, R.mipmap.mi3, R.mipmap.mi4, R.mipmap.mi5, R.mipmap.mi6, R.mipmap.mi7, R.mipmap.mi8, R.mipmap.mi9, R.mipmap.mi10
    };

    private int[] texts = {
            R.string.word_mi1, R.string.word_mi2, R.string.word_mi3, R.string.word_mi4, R.string.word_mi5, R.string.word_mi6, R.string.word_mi7, R.string.word_mi8, R.string.word_mi9, R.string.word_mi10
    };

    private List<Integer> listIcon = new ArrayList<Integer>();
    private List<Integer> listText = new ArrayList<Integer>();

    public MiningMenuAdapter(Context context) {
        mContext = context;
        for (int i = 0; i < 10; i++) {
            listIcon.add(icons[i]);
            listText.add(texts[i]);
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_grid_menu, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        holder.wEqualsHImageView.setImageResource(listIcon.get(position));
        holder.textView.setText(listText.get(position));
        holder.wEqualsHImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("order", position);
                intent.setClass(mContext, VideoAndDocumentActivity.class);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return listIcon.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        public TextView textView;
        public WEqualsHImageView wEqualsHImageView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.main_item_text);
            wEqualsHImageView = (WEqualsHImageView) itemView.findViewById(R.id.main_item_icon);
        }
    }
}
